package com.data.codegenerate.generate.util;

import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

public class SimpleFormat {
    public static String underlineToHump(String para) {
        StringBuilder sb = new StringBuilder();
        String[] split = para.split("_");
        for (String str : split) {
            if (!para.contains("_")) {
                sb.append(str);
            } else if (sb.length() == 0) {
                sb.append(str.toLowerCase());
            } else {
                sb.append(str.substring(0, 1).toUpperCase());
                sb.append(str.substring(1).toLowerCase());
            }
        }
        return sb.toString();
    }

    public static String humpToUnderline(String para) {
        int i = 0;
        StringBuilder sb = new StringBuilder(para);
        if (!para.contains("_")) {
            for (int i2 = 0; i2 < para.length(); i2++) {
                if (Character.isUpperCase(para.charAt(i2))) {
                    sb.insert(i2 + i, "_");
                    i++;
                } else {
                    i = i;
                }
            }
        }
        if (sb.toString().toLowerCase().startsWith("_")) {
            return sb.toString().toLowerCase().substring(1);
        }
        return sb.toString().toLowerCase();
    }

    public static String humpToShortbar(String para) {
        int i = 0;
        StringBuilder sb = new StringBuilder(para);
        if (!para.contains("-")) {
            for (int i2 = 0; i2 < para.length(); i2++) {
                if (Character.isUpperCase(para.charAt(i2))) {
                    sb.insert(i2 + i, "-");
                    i++;
                } else {
                    i = i;
                }
            }
        }
        if (sb.toString().toLowerCase().startsWith("-")) {
            return sb.toString().toLowerCase().substring(1);
        }
        return sb.toString().toLowerCase();
    }

    public static void main(String[] args) {
        System.out.println(humpToShortbar("jeecgDemo"));
    }

    public String number(Object obj) {
        if (obj == null || obj.toString().length() == 0) {
            obj = 0;
        }
        if (obj.toString().equalsIgnoreCase("NaN")) {
            return "NaN";
        }
        return new DecimalFormat("0.00").format(Double.parseDouble(obj.toString()));
    }

    public String number(Object obj, String pattern) {
        if (obj == null || obj.toString().length() == 0) {
            obj = 0;
        }
        if (obj.toString().equalsIgnoreCase("NaN")) {
            return "NaN";
        }
        return new DecimalFormat(pattern).format(Double.parseDouble(obj.toString()));
    }

    public String round(Object obj) {
        if (obj == null || obj.toString().length() == 0) {
            obj = 0;
        }
        if (obj.toString().equalsIgnoreCase("NaN")) {
            return "NaN";
        }
        return new DecimalFormat("0").format(Double.parseDouble(obj.toString()));
    }

    public String currency(Object obj) {
        if (obj == null || obj.toString().length() == 0) {
            obj = 0;
        }
        return NumberFormat.getCurrencyInstance(Locale.CHINA).format(obj);
    }

    public String timestampToString(Object obj, String pattern) {
        if (obj == null) {
            return "";
        }
        try {
            return new SimpleDateFormat(pattern).format(new SimpleDateFormat("dd-MM月 -yy").parse(obj.toString()));
        } catch (ParseException e) {
            e.printStackTrace();
            return "error";
        }
    }

    public String percent(Object obj) {
        if (obj == null || obj.toString().length() == 0) {
            obj = 0;
        }
        if (obj.toString().equalsIgnoreCase("NaN")) {
            return "";
        }
        return NumberFormat.getPercentInstance(Locale.CHINA).format(obj);
    }

    public String date(Object obj, String pattern) {
        if (obj == null) {
            return "";
        }
        return new SimpleDateFormat(pattern).format(obj);
    }

    public String date(Object obj) {
        if (obj == null) {
            return "";
        }
        return DateFormat.getDateInstance(1, Locale.CHINA).format(obj);
    }

    public String time(Object obj) {
        if (obj == null) {
            return "";
        }
        return DateFormat.getTimeInstance(3, Locale.CHINA).format(obj);
    }

    public String datetime(Object obj) {
        if (obj == null) {
            return "";
        }
        return DateFormat.getDateTimeInstance(1, 3, Locale.CHINA).format(obj);
    }

    public String getInStrs(List<String> params) {
        StringBuffer stringBuffer = new StringBuffer();
        Iterator<String> it = params.iterator();
        while (it.hasNext()) {
            stringBuffer.append("'" + it.next() + "',");
        }
        String stringBuffer2 = stringBuffer.toString();
        if (!"".equals(stringBuffer2) || stringBuffer2.endsWith(",")) {
            return stringBuffer2.substring(0, stringBuffer2.length() - 1);
        }
        return null;
    }
}
